function mitt(all = new Map()) {
  return {
    all,
    on(eventType, handler) {
      if (typeof eventType !== 'string' || typeof handler !== 'function') return;
      const handlers = all.get(eventType);
      handlers ? handlers.add(handler) : all.set(eventType, new Set([handler]));
    },
    off(eventType, handler) {
      if (typeof eventType !== 'string' || typeof handler !== 'function') return;
      const handlers = all.get(eventType);
      handlers.delete(handler);
    },
    emit(eventType, params) {
      if (typeof eventType !== 'string') return;
      const handlers = all.get(eventType);
      for (let handler of handlers) {
        handler(params);
      }
    }
  };
}

const mitter = mitt();

const foo = a => {
  console.log('foo', a);
  return 'foo';
};

mitter.on('testone', foo);
console.log(mitter.all);

// mitter.off('testone', foo);
// console.log(mitter.all);

mitter.emit('testone', 100);
